<?php
/**
 * Created by PhpStorm.
 * User: DL
 * Date: 2018/8/27
 * Time: 10:42
 */

include($_SERVER['DOCUMENT_ROOT']."/inc/config.php");
include($_SERVER['DOCUMENT_ROOT']."/inc/db.php");
if(empty($_REQUEST['id'])){
    echo '非法请求!';exit;
}
$id=$_REQUEST['id'];
$dataCount=0;
$pageSize=10;
$pageNo=1;
if(!empty($_REQUEST['pageNo'])){
    $pageNo=$_REQUEST['pageNo'];
}
$where=" order by id desc limit ".($pageNo-1)*$pageSize.",".$pageSize;
$pageNum=0;
$sql="select * from company_setup where client_id=$id";
$sqlCount="select count(`id`) from company_setup where client_id=$id";
$sqlCount.=$where;
mysql_query('set names utf8');
$result=mysql_query($sqlCount);
while ($row=mysql_fetch_row($result)){
    $dataCount=$row[0];
}
$pageNum=ceil($dataCount/$pageSize);
$sql.=$where;
$data['data']=array();
$result=mysql_query($sql);
$i=0;
while ($assoc=mysql_fetch_assoc($result)){
    $id=$assoc['id'];
    $data['data'][$i]['id']=$id;
    $data['data'][$i]['en_name1']=$assoc['en_name1'];
    $data['data'][$i]['cn_name1']=$assoc['cn_name1'];
    $data['data'][$i]['en_name2']=$assoc['en_name2'];
    $data['data'][$i]['cn_name2']=$assoc['cn_name2'];
    $data['data'][$i]['en_name3']=$assoc['en_name3'];
    $data['data'][$i]['cn_name3']=$assoc['cn_name3'];
    $data['data'][$i]['sec_use']=$assoc['sec_use'];
    $data['data'][$i]['sec_use_other']=$assoc['sec_use_other'];
    $data['data'][$i]['sec_addr']=$assoc['sec_addr'];
    $data['data'][$i]['sec_addr_other']=$assoc['sec_addr_other'];
    $data['data'][$i]['client_id']=$assoc['client_id'];
    $data['data'][$i]['addeddate']=$assoc['addeddate'];
    $data['data'][$i]['name']=$assoc['name'];
    $data['data'][$i]['email']=$assoc['email'];
    $data['data'][$i]['tel']=$assoc['tel'];
    //董事
    $sqlPartner="select * from comp_partner where img_comp_id=$id";
    $resultP=mysql_query($sqlPartner);
    $p=0;
    while ($row=mysql_fetch_assoc($resultP)){
        $data['data'][$i]['partner'][$p]['img_id']=$row['img_id'];
        $data['data'][$i]['partner'][$p]['img_comp_id']=$row['img_comp_id'];
        $data['data'][$i]['partner'][$p]['img_path']='http://app.yabez.hk/images/partner/'.$row['img_path'];
        $data['data'][$i]['partner'][$p]['img_addr_path']='http://app.yabez.hk/images/partner/'.$row['img_addr_path'];
        $data['data'][$i]['partner'][$p]['img_date']=$row['img_date'];
        $data['data'][$i]['partner'][$p]['img_sort']=$row['img_sort'];
        $p++;
    }
    //股东
    $sqlDirector="select * from comp_director where img_comp_id=$id";
    $resultD=mysql_query($sqlDirector);
    $d=0;
    while ($row=mysql_fetch_assoc($resultD)){
        $data['data'][$i]['director'][$d]['img_id']=$row['img_id'];
        $data['data'][$i]['director'][$d]['img_comp_id']=$row['img_comp_id'];
        $data['data'][$i]['director'][$d]['img_path']='http://app.yabez.hk/images/director/'.$row['img_path'];
        $data['data'][$i]['director'][$d]['img_addr_path']='http://app.yabez.hk/images/director/'.$row['img_addr_path'];
        $data['data'][$i]['director'][$d]['img_date']=$row['img_date'];
        $data['data'][$i]['director'][$d]['img_sort']=$row['img_sort'];
        $d++;
    }
    $i++;
}

$data['pageNum']=$pageNum;
$data['pageNo']=$pageNo;
$data['dataCount']=$dataCount;

echo json_encode($data);exit;